package com.langtags.gears;

import java.util.Map;

public class FCRecTemplate {

	
	static String startTemplate(Map<String,Map> context){
		Map startTypes = context.get("startTypes");
		StringBuilder sb = new StringBuilder();
		if (startTypes != null){
			for(Object key:startTypes.keySet()){
				String startType = (String)key;
				String type = (String)startTypes.get(key);
				appendStart(sb, startType, type);
			}
		}
		
		Map startFunctions = context.get("startFunctions");
		if (startFunctions != null){
			for (Object key:startFunctions.keySet()){
				String startFunction = (String)key;
				String type = (String)startFunctions.get(key);
				appendFunction(sb, startFunction, type);
			}
		}
		Map startConstants = context.get("startConstants");
		if (startConstants != null){
			for (Object key:startConstants.keySet()){
				String constants = (String)key;
				appendConstants(sb, constants);
			}
		}
		return sb.toString();
	}
	static String template(Map<String,Map> context){
		Map methods = context.get("methods");
		StringBuilder sb = new StringBuilder();
		if (methods != null){
			for(Object key:methods.keySet()){
				String method = (String)key;
				String type = (String)methods.get(key);
				appendMethod(sb, method, type);
			}
		}
		Map properties = context.get("properties");
		if (properties != null){
			for (Object key:properties.keySet()){
				String property = (String)key;
				String type = (String)properties.get(key);
				appendProperty(sb, property, type);
			}
		}
		return sb.toString();
	}
	private static void appendConstants(StringBuilder sb,String constants){
		sb.append("#/---------------------------------------------\r\n");
		sb.append("#!");
		sb.append(constants);
		sb.append("\r\n");
		sb.append("#@type=unspecified\r\n");
		sb.append("#@iesupport=y\r\n");
		sb.append("#@nssupport=y\r\n");
		sb.append("#@ecmasupport=y\r\n");
		sb.append("#@fc=doneclass\r\n");
	}
	private static void appendStart(StringBuilder sb,String startType,String type){
		sb.append("#/---------------------------------------------\r\n");
		sb.append("#!");
		sb.append(startType);
		sb.append("\r\n");
		sb.append("#@type=unspecified\r\n");
		sb.append("#@iesupport=y\r\n");
		sb.append("#@nssupport=y\r\n");
		sb.append("#@ecmasupport=y\r\n");
		sb.append("#@fc=");
		sb.append(type);
		sb.append("\r\n");
	}
	private static void appendFunction(StringBuilder sb,String function,String type){
		sb.append("#/---------------------------------------------\r\n");
		sb.append("#!");
		sb.append(function);
		sb.append("\r\n");
		sb.append("#@type=unspecified\r\n");
		sb.append("#@iesupport=y\r\n");
		sb.append("#@nssupport=y\r\n");
		sb.append("#@ecmasupport=y\r\n");
		sb.append("#@fc=");
		sb.append(type);
		sb.append("\r\n");
	}
	
	private static void appendProperty(StringBuilder sb,String property,String type){
		sb.append("#/---------------------------------------------\r\n");
		sb.append("#!");
		sb.append(property);
		sb.append("\r\n");
		sb.append("#@type=unspecified\r\n");
		sb.append("#@iesupport=y\r\n");
		sb.append("#@nssupport=y\r\n");
		sb.append("#@ecmasupport=y\r\n");
		sb.append("#@fc=");
		sb.append(type);
		sb.append("\r\n");
	}
	private static void appendMethod(StringBuilder sb,String method,String type){
		sb.append("#/---------------------------------------------\r\n");
		sb.append("#!");
		sb.append(method);
		sb.append("\r\n");
		sb.append("#@type=method\r\n");
		sb.append("#@iesupport=y\r\n");
		sb.append("#@nssupport=y\r\n");
		sb.append("#@ecmasupport=y\r\n");
		sb.append("#@fc=");
		sb.append(type);
		sb.append("\r\n");
	}

}
